import { VueComponent,Prop,Watch } from 'vue-typescript'

//This is overkill but typescript is great! :)
class Child{
    path:string;
    name:string;
    show:boolean;

    constructor(path:string,name:string,show:boolean){
        this.path = path;
        this.name = name;
        this.show = show;
    }
}
class Link {
    icon:string;
    name:string;
    path:string;
    show:boolean;
    isA:boolean;
    isB:boolean;
    childs:Array<Child>;

    constructor(icon:string,name:string, path:string,show:boolean,isA:boolean,isB:boolean,childs?:Array<Child>){
        this.icon = icon;
        this.name = name;
        this.path = path;
        this.show = show;
        this.isA = isA;
        this.isB = isB;
        this.childs= childs;
    }
}
@VueComponent({
    template:require('./aside.html'),
    events:{},
    methods:{
        showChildMenu:function(link,links){
            for(var i=0;i<links.length;i++){
                for(var child in links[i].childs){
                    console.log(links[i].childs[child]);
                    if(links[i].childs[child].show==true){
                        links[i].childs[child].show=false;
                    }
                }
            }
            if(link.show==false){
                link.show=true;
                link.isA=false;
                link.isB=true;
            }
            else{
                link.show=false;
                link.isA=true;
                link.isB=false;
            }
         },
         showIcon:function(Child,links){
             //console.log(links);
             for(var i=0;i<links.length;i++)
             {
                 //console.log(links[i].childs);
                 for(var child in links[i].childs){
                     console.log(links[i].childs[child]);
                     if(links[i].childs[child].show==true){
                         links[i].childs[child].show=false;
                     }
                 }
             }
              if(Child.show==false){
                 Child.show=true;
             }
            
         }
    }
})

export class Aside extends Vue{
    @Prop
    links:Link[] = [
        new Link('fa fa-truck fa-fw fa-lg fa-flip-horizontal','待发物料', '/home',false,true,false),
        new Link('fa fa-fw fa-lg fa-commenting-o','询价', '/inquiry',false,true,false,
            [new Child('/inquiry_issue','询价发布',false),
            new Child('/xj2','待发询价',false),
            new Child('/xj3','报价信息',false)]),
        new Link('fa fa-truck fa-fw fa-lg','发货','fh.html',false,true,false,
            [new Child('/order_issue','发货发布',false),
            new Child('/fh2','待发货',false),
            new Child('/fh3','发货信息',false)]),
        new Link('fa fa-jpy fa-fw fa-lg','财务统计','cw.html',false,true,false,
            [new Child('/cw1','询价统计',false),
            new Child('/cw2','发货统计',false)])
    ]

    @Watch('$route.path')
    pathChanged(){
        console.log('Changed current path to: ' + this.$route.path);
    }
    
}